package operation.observer.objs;

import operation.observer.abs.Observer;
import operation.observer.abs.Subject;

import java.util.ArrayList;

public class WeatherData extends Subject {
    private float temperature;
    private float humidity;

    public WeatherData() {
        list = new ArrayList<>();
    }

    public void updateData(float t, float h) {
        this.temperature = t;
        this.humidity = h;
        notifyObservers();
    }

    @Override
    public void registerObserver(Observer o) {
        list.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        list.remove(o);
    }

    @Override
    public void notifyObservers() {
        for (Observer o : list) {
            o.update(temperature, humidity);
        }
    }
}
